package sandbox;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

public class ObjectDto implements Serializable {

    public static class DtoAttribute<V> implements Serializable {
        private String name;
        private V value;

        public DtoAttribute(String name, V value) {
            this.name = name;
            this.value = value;
        }

        public String getName() {
            return name;
        }

        public V getValue() {
            return value;
        }
    }

    private final List<DtoAttribute> attributes;

    public ObjectDto(DtoAttribute... attributes) {
        this.attributes = new LinkedList<DtoAttribute>();
        addAttributes(Arrays.asList(attributes));
    }

    public List<DtoAttribute> getAttributes() {
        return attributes;
    }

    public void clearAttributes() {
        attributes.clear();
    }

    public void addAttribute(DtoAttribute attribute) {
        attributes.add(attribute);
    }

    public void addAttributes(Collection<? extends DtoAttribute> attributes) {
        this.attributes.addAll(attributes);
    }

    public void setAttributes(Collection<? extends DtoAttribute> attributes) {
        clearAttributes();
        addAttributes(attributes);
    }
}
